<template>
  <div class="approvalRecord">
    <TitleName
      title="审批记录"
      icon="i-carbon-bookmark-filled"
      class="title"
    ></TitleName>
    <el-row class="mt-50px">
      <el-col
        v-for="(o, index) in examineObj"
        :key="o"
        :span="10"
        :offset="index > 0 ? 2 : 1"
        ><!-- 
          v-if="o.status != '流程未发起'" -->
        <el-card shadow="hover" class="w-100% pointer" @click="handelClick(o)">
          <el-row class="leading-30px">
            <el-col :span="14">
              <svg-icon
                :icon-class="index > 0 ? 'svg_tbfk' : 'svg_xmcj'"
                class="w-30px h-30px align-middle"
              />
              <span
                class="text-#000 leading-30px ml-10px text-16px font-bold align-bottom"
                >{{ o.businessldsName }}</span
              >
            </el-col>
            <el-col :span="10" class="text-right text-15px">
              <i
                :class="
                  o.status == '审批通过'
                    ? 'h-8px w-8px bg-#fe9400 inline-block rounded'
                    : o.status == '流程未发起'
                    ? 'h-8px w-8px bg-#ccc inline-block rounded'
                    : 'h-8px w-8px bg-#10d070 inline-block rounded'
                "
              ></i>
              {{ o.status }}
            </el-col>
          </el-row>
          <div class="mt-11px text-15px" style="border-top: 1px solid #ccc">
            <p>
              创建人<span class="text-#666 ml-15px">{{ o.createBy }}</span>
            </p>
            <p>
              创建时间<span class="text-#666 ml-15px">{{
                parseTime(o.createTime)
              }}</span>
            </p>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>
<script setup name="ApprovalRecord">
import { useRoute, useRouter } from 'vue-router'
import { reactive, toRefs } from 'vue'
import * as Api from '@/api/projectManage/project'
const router = useRouter()
const route = useRoute()
const { proxy, type } = getCurrentInstance()
const props = defineProps({
  baseDetail: {
    required: true,
    type: Object || Array,
    default: () => {
      return {}
    }
  }
})
const examineObj = ref([]) //项目、投标反馈结果
watch(
  () => props.baseDetail,
  val => {
    if (val && route.name == 'PurchaseOrderDetails') {
      getList()
    }
  },
  {
    immediate: true
  }
)
function getList() {
  examineObj.value = [
    {
      businessldsName: '创建审批',
      businesslds: props.baseDetail.id,
      processed: false,
      createBy: props.baseDetail.createName,
      createTime: props.baseDetail.createTime
    }
  ]

  // 获取项目和投标结果反馈等模块审批状态接口
  let businessldsVal = props.baseDetail.id + ','
  Api.getProStatusByBusinessIds(businessldsVal).then(res => {
    examineObj.value[0] = {
      ...examineObj.value[0],
      ...res.data[0]
    }
    examineObj.value[0].processed = res.data[0]?.taskId ? true : false
    examineObj.value[0].createBy = res.data[0]?.createBy
      ? res.data[0]?.createBy
      : props.baseDetail.createName
    examineObj.value[0].createTime = res.data[0]?.createTime
      ? res.data[0]?.createTime
      : props.baseDetail.createTime
    examineObj.value[0].status =
      res.data[0]?.status == '流程未发起' ? '申请' : res.data[0]?.status
  })
}
/** 点击调整详情页 */
const handelClick = row => {
  if (row.statusValue == '00') {
    router.push({
      path: '/source/sourceModules/editPurchaseOrder',
      query: { purchaseOrderId: row.businesslds }
    })
  } else {
    router.push({
      path: '/process/workDetail',
      query: {
        procInsId: row.proInsId, //发起流程的id
        taskId: row.taskId, //任务id(每个环节审批人的任务id)
        processed: row.processed //这个是判断是否是已办待办
      }
    })
  }
}
</script>
